home *** CD-ROM | disk | FTP | other *** search
/ Dynamic HTML Construction Kit / Dynamic HTML Construction Kit.iso / earthlink / nscomm / java40.jar / java / text / SimpleTextBoundary.class (.txt) < prev    next >
Encoding:
Java Class File  |  1997-11-03  |  2.7 KB  |  170 lines

  1. package java.text;
  2.  
  3. final class SimpleTextBoundary extends BreakIterator {
  4.    private int pos;
  5.    private CharacterIterator text;
  6.    private TextBoundaryData data;
  7.  
  8.    protected SimpleTextBoundary(TextBoundaryData var1) {
  9.       this.data = var1;
  10.       this.text = new StringCharacterIterator("");
  11.       this.pos = this.text.getBeginIndex();
  12.    }
  13.  
  14.    public boolean equals(Object var1) {
  15.       if (this == var1) {
  16.          return true;
  17.       } else if (!(var1 instanceof SimpleTextBoundary)) {
  18.          return false;
  19.       } else {
  20.          SimpleTextBoundary var2 = (SimpleTextBoundary)var1;
  21.          if (this.data.getClass() != var2.data.getClass()) {
  22.             return false;
  23.          } else if (this.hashCode() != var2.hashCode()) {
  24.             return false;
  25.          } else if (this.pos != var2.pos) {
  26.             return false;
  27.          } else {
  28.             return this.text.equals(var2.text);
  29.          }
  30.       }
  31.    }
  32.  
  33.    public int hashCode() {
  34.       return this.getClass().hashCode() ^ this.text.hashCode();
  35.    }
  36.  
  37.    public Object clone() {
  38.       try {
  39.          SimpleTextBoundary var1 = (SimpleTextBoundary)super.clone();
  40.          var1.text = (CharacterIterator)this.text.clone();
  41.          return var1;
  42.       } catch (InternalError var2) {
  43.          throw new InternalError();
  44.       }
  45.    }
  46.  
  47.    public CharacterIterator getText() {
  48.       return this.text;
  49.    }
  50.  
  51.    public void setText(String var1) {
  52.       this.text = new StringCharacterIterator(var1);
  53.       this.pos = this.text.getBeginIndex();
  54.    }
  55.  
  56.    public void setText(CharacterIterator var1) {
  57.       this.text = var1;
  58.       this.pos = this.text.getBeginIndex();
  59.    }
  60.  
  61.    public int first() {
  62.       this.pos = this.text.getBeginIndex();
  63.       return this.pos;
  64.    }
  65.  
  66.    public int last() {
  67.       this.pos = this.text.getEndIndex();
  68.       return this.pos;
  69.    }
  70.  
  71.    public int next(int var1) {
  72.       int var2 = this.current();
  73.       if (var1 < 0) {
  74.          for(int var3 = var1; var3 < 0 && var2 != -1; ++var3) {
  75.             var2 = this.previous();
  76.          }
  77.       } else {
  78.          for(int var4 = var1; var4 > 0 && var2 != -1; --var4) {
  79.             var2 = this.next();
  80.          }
  81.       }
  82.  
  83.       return var2;
  84.    }
  85.  
  86.    public int previous() {
  87.       if (this.pos <= this.text.getBeginIndex()) {
  88.          return -1;
  89.       } else {
  90.          int var1 = this.pos;
  91.          this.pos = this.previousSafePosition(this.pos - 1);
  92.          int var2 = this.pos;
  93.  
  94.          for(int var3 = this.next(); var3 < var1 && var3 != -1; var3 = this.next()) {
  95.             var2 = var3;
  96.          }
  97.  
  98.          this.pos = var2;
  99.          return this.pos;
  100.       }
  101.    }
  102.  
  103.    public int next() {
  104.       int var1 = this.pos;
  105.       if (this.pos < this.text.getEndIndex()) {
  106.          this.pos = this.nextPosition(this.pos);
  107.          var1 = this.pos;
  108.       } else {
  109.          var1 = -1;
  110.       }
  111.  
  112.       return var1;
  113.    }
  114.  
  115.    public int following(int var1) {
  116.       if (var1 >= this.text.getBeginIndex() && var1 < this.text.getEndIndex()) {
  117.          this.pos = this.previousSafePosition(var1);
  118.  
  119.          int var2;
  120.          do {
  121.             var2 = this.next();
  122.          } while(var2 <= var1 && var2 != -1);
  123.  
  124.          return var2;
  125.       } else {
  126.          throw new IllegalArgumentException("nextBoundaryAt offset out of bounds");
  127.       }
  128.    }
  129.  
  130.    public int current() {
  131.       return this.pos;
  132.    }
  133.  
  134.    private int previousSafePosition(int var1) {
  135.       int var2 = this.text.getBeginIndex();
  136.       int var3 = this.data.backward().initialState();
  137.  
  138.       for(char var4 = this.text.setIndex(var1); var4 != '\uffff' && !this.data.backward().isEndState(var3); var4 = this.text.previous()) {
  139.          var3 = this.data.backward().get(var3, this.mappedChar(var4));
  140.          if (this.data.backward().isMarkState(var3)) {
  141.             var2 = this.text.getIndex();
  142.          }
  143.       }
  144.  
  145.       return var2;
  146.    }
  147.  
  148.    private int nextPosition(int var1) {
  149.       int var2 = this.text.getEndIndex();
  150.       int var3 = this.data.forward().initialState();
  151.  
  152.       for(char var4 = this.text.setIndex(var1); var4 != '\uffff' && !this.data.forward().isEndState(var3); var4 = this.text.next()) {
  153.          var3 = this.data.forward().get(var3, this.mappedChar(var4));
  154.          if (this.data.forward().isMarkState(var3)) {
  155.             var2 = this.text.getIndex();
  156.          }
  157.       }
  158.  
  159.       if (this.data.forward().isEndState(var3)) {
  160.          return var2;
  161.       } else {
  162.          return this.text.current() != '\uffff' ? var2 : this.text.getEndIndex();
  163.       }
  164.    }
  165.  
  166.    protected int mappedChar(char var1) {
  167.       return this.data.map().mappedChar(var1);
  168.    }
  169. }
  170.